package com.sumainfor.pc.market.controller.Feign;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.service.HousingService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/6/12 13:15
 * @Description:
 */
@RestController
@RequestMapping("/key/hou")
public class HousingFeignController {

    @Autowired
    HousingService HousingService;

    /**
     * 功能描述:
     * 根据房源配置获取所有房源资料(字段可扩展)
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 13:17
     */
    @GetMapping("/getAllHousingConLists")
    public JsonResult getAllHousingConLists() {
        return JsonResult.success(HousingService.getAllHousingConLists());
    }

    /**
     * 功能描述:
     * 获取所有房源资料(字段可扩展)
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/17 18:54
     */
    @GetMapping("/getAllHousingLists")
    public List<Map<String, Object>> getAllHousingLists() {
        return HousingService.getAllHousingLists();
    }

    /**
     * 根据房源编号过滤这个项目下的房源信息
     *
     * @param params hIds :Array
     *               val :String
     *               col :String
     *               where :String
     * @return
     */
    @PostMapping("/selectComIdByHId")
    public JsonResult selectComIdByHId(@RequestBody Map<String, Object> params) {
        List<String> hIds = (List<String>) params.get("hIds");
        String val = (String) params.get("val");
        String col = (String) params.get("col");
        String where = (String) params.get("where");
        if (CollectionUtils.isEmpty(hIds) || StringUtils.isBlank(col) || StringUtils.isBlank(where) || StringUtils.isBlank(val)) {
            return JsonResult.errorForEmpty();
        }
        return HousingService.selectComIdByHId(hIds, val, col, where);
    }

    /**
     * 根据房源主编号查询房源基本信息资料数据
     *
     * @param hIds
     * @return
     */
    @PostMapping("/selectHousingDetailByArray")
    public JsonResult selectHousingDetailByArray(@RequestBody List<String> hIds) {
        if (CollectionUtils.isEmpty(hIds)) {
            return JsonResult.errorForEmpty();
        }
        return HousingService.selectHousingDetailByArray(hIds);
    }

    /**
     * 查找房间号通过房源配置编号
     *
     * @param ids
     * @return
     */
    @PostMapping("/getHousingRoom")
    public JsonResult getHousingRoom(@RequestBody List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return JsonResult.errorForEmpty();
        }
        return HousingService.getHousingRoom(ids);
    }

    /**
     * 根据服务中心编号，项目编号。楼号。房号。室号获取房源主表和房源详表
     * @return
     */
    @PostMapping("/getMiAndComAndBuiAndRoomAndHouList")
    public List<Map<String,Object>> getMiAndComAndBuiAndRoomAndHouList(@RequestBody Map<String,Object>params) {
        return HousingService.getMiAndComAndBuiAndRoomAndHouList(params);
    }

    @PostMapping("/getHouIncid")
    public List<Map<String,Object>> getHouIncid(@RequestBody Map<String,Object> params){
        return HousingService.getHouIncid(params);
    }


}
